package cn.interestingshop.dao.user;

import cn.interestingshop.dao.BaseDao;
import cn.interestingshop.model.entity.User;

import java.sql.SQLException;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/3/10 9:14
 **/
public class UserDaoImpl extends BaseDao<User> implements UserDao{
	@Override
	public User findUserByAccount(String account){
		String sql ="SELECT id, account, nick_name, password, gender, id_card_no, email, phone, type, open_id FROM t_user WHERE account = ?;";
		User user = new User();
		try {
			return super.getResult(sql,user,new Object[]{account});
		} catch (SQLException throwables) {
			throwables.printStackTrace();
		}
		return null;
	}

	@Override
	public int add(User user){
		String sql=" INSERT into t_user(account,nick_name,password,gender,id_card_no,email,phone,type,open_id)" +
				" values(?,?,?,?,?,?,?,?,?) ";
		Object[] params = {user.getAccount(),
				user.getNick_name(),
				user.getPassword(),
				user.getGender(),
				user.getId_card_no(),
				user.getEmail(),
				user.getPhone(),
				0,
				null};
		try{
			return super.executeUpdate(sql, params);
		}catch (SQLException e){
			e.printStackTrace();
		}
		return 0;
	}
}
